package com.cci.kangdao.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cci.kangdao.dto.request.GetLicensePlateNumberByEsnRequest;
import com.gexin.fastjson.JSON;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.cci.kangdao.service.FeedbackService;
import com.cci.kangdao.utilTool.ParameterTool;

@Controller
public class FeedBackRest {

	private final static Logger log = Logger.getLogger(FeedBackRest.class);
	
	@Autowired
	private FeedbackService feedbackService;
	
	/**
	 * 获取意见反馈基础数据
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/getFeedBackMD.aspx")
	public ModelAndView getRolesList(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.getFeedBackMD(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}
	
	/**
	 * 提交意见反馈接口
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/submitFeedbackV4.aspx")
	public ModelAndView authCheck(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.submitFeedbackV4(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
		return null;
	}

	/**
	 * 提交意见反馈接口
	 *
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/submitFeedbackV5.aspx", method = RequestMethod.POST)
	public ModelAndView authCheckFeedback(HttpServletRequest request,
										  HttpServletResponse response, @RequestBody String paramStr) {
		try {
			Map map = JSON.parseObject(paramStr, Map.class);
//			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.submitFeedbackV4(map);
		} catch (Exception ex) {
			log.error(ex.getMessage(), ex);

			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return null;
	}
	/**
	 * 获取意见反馈列表
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="/getFeedBackList.aspx")
	public void getFeedBackList(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			feedbackService.getFeedBackList(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
	}
	
	/**
	 * 获取意见反馈详情
	 * @param request
	 * @param response
	 */
	@RequestMapping(value="/getFeedBackInfo.aspx")
	public void getFeedBackInfo(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			feedbackService.getFeedBackInfo(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
	}
	
	/**
	 * 获取工单编码接口
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/getBillNo.aspx")
	public void getBillNo(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			feedbackService.getBillNo(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
	}
	
	/**
	 * 获取未读消息数目接口
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/getUnReadMsgCount.aspx")
	public void getUnReadMsgCount(HttpServletRequest request,
			HttpServletResponse response) {
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			feedbackService.getUnReadMsgCount(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);	
			
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);	
		}
	}

	//上传照片单独上传接口   本接口作用单张单张照片上传   返回照片url   前端拼成字符串   传给后台   后台保存数据库
	@RequestMapping(value="/fileUpload.aspx")
	public ModelAndView fileUpload(HttpServletRequest request, HttpServletResponse response){
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.fileUpload(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return  null;
	}


	//新上传照片单独上传接口   本接口作用单张单张照片上传   返回照片url   前端拼成字符串   传给后台   后台保存数据库
	//修改文件名称拼接格式
	@RequestMapping(value="/newFileUpload.aspx")
	public ModelAndView newFileUpload(HttpServletRequest request, HttpServletResponse response){
		try{
			Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
			map.put("response", response);
			map.put("request", request);
			return feedbackService.newFileUpload(map);
		}catch(Exception ex){
			log.error(ex.getMessage(),ex);
			String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
			ParameterTool.writeResponse(response, msg);
		}
		return  null;
	}

	//诊断维修  校验FC/SPN、FMI或者症状后如果不存在服务手册      调用这个接口进行意见反馈
	@RequestMapping(value="/notExistHandBookConfigFeedBack.aspx")
	public ModelAndView notExistHandBookConfigFeedBack( HttpServletRequest request, HttpServletResponse response,@RequestBody String contentJson)throws Exception{
		log.info("接口传参为"+contentJson);
		Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
		map.put("response", response);
		map.put("request", request);
		map.put("contentJson",contentJson);
		return feedbackService.notExistHandBookConfigFeedBack(map);
	}
}
